package com.xoms.front.service.impl;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.xoms.front.controller.res.BaseResult;
import com.xoms.front.model.print.PrintDepositBean;
import com.xoms.front.service.PrintService;
import com.xoms.front.util.net.HttpManagerImpl;
import com.xoms.util.DateUtil;

@Service
public class PrintServiceImpl implements PrintService {
	private static final Logger logger = LoggerFactory.getLogger(PrintServiceImpl.class);

	@Override
	public BaseResult printOrder(String orderId) {
		BaseResult result = new BaseResult();
		
		StringBuffer printBean = new StringBuffer();
		PrintDepositBean de = new PrintDepositBean();
		de.setOrderNo("KC2018032102221");
		de.setPhone("17610075502");
		de.setPrintId("123123123123123");
		de.setPrintNum("1");
		de.setPrintType(1);
		de.setSeller("张三");
		de.setStoreEndTime(DateUtil.getDate("2018-02-01"));
		de.setStoreLength("90");
		de.setStoreStartTime(DateUtil.getDate("2018-05-01"));
		de.setTitle("客存打印");
		printBean.append("账单号：" + de.getOrderNo());
		printBean.append("\r");
		printBean.append("手机号：" + de.getPhone());
		printBean.append("\r");
		printBean.append("客存时间：" + de.getStoreStartTime());
		printBean.append("\r");
		printBean.append("保存有效期限（" + de.getStoreLength()+"天)：" + de.getStoreEndTime());
		printBean.append("\r");
		printBean.append("______________________\r\n");
		printBean.append("______________________\n");
		
		Map<String, Object> print = new HashMap<>();
		print.put("billingbody", printBean);
		String resultStr = HttpManagerImpl.getInstance().post("http://192.168.1.21:6090", printBean.toString());
		System.out.println(resultStr);
		result.setFlag("打印成功".equals(resultStr));
		return result;
	}

	public static void main(String[] args) throws UnsupportedEncodingException {
		StringBuffer printBean = new StringBuffer();
		PrintDepositBean de = new PrintDepositBean();
		de.setOrderNo("KC2018032102221");
		de.setPhone("17610075502");
		de.setPrintId("123123123123123");
		de.setPrintNum("1");
		de.setPrintType(1);
		de.setSeller("张三");
		de.setStoreEndTime(DateUtil.getDate("2018-02-01"));
		de.setStoreLength("90");
		de.setStoreStartTime(DateUtil.getDate("2018-05-01"));
		de.setTitle("客存打印");
		printBean.append("账单号：" + de.getOrderNo());
		printBean.append("\r");
		printBean.append("手机号：" + de.getPhone());
		printBean.append("\r");
		printBean.append("客存时间：" + de.getStoreStartTime());
		printBean.append("\r");
		printBean.append("保存有效期限（" + de.getStoreLength()+")天：" + de.getStoreEndTime());
		printBean.append("\r");
		printBean.append("____________________________________\r");
		printBean.append("名称            数量              价格\r");
		printBean.append("啤酒            20               200\r");
		printBean.append("____________________________________\r");
		
		Map<String, Object> print = new HashMap<>();
		print.put("BillBody", printBean.toString());
		print.put("BillHead", "客存小票");
		String resultStr = HttpManagerImpl.getInstance().post("http://192.168.0.117:6090", "BillBody="+printBean.toString()+"BillHead：客存小票");
		System.out.println(resultStr);

	}

}
